package com.kaili.basic.bean;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.kaili.basic.pojo.entity.BasePdaExport;
import org.springframework.stereotype.Component;

import java.io.InputStream;
import java.util.List;

@Component
public class ImportPda extends BaseImport {

    @Override
    public void doAnalyze(InputStream inputStream) throws Exception {

        List<BasePdaExport> infos = ExcelImportUtil.importExcel(inputStream, BasePdaExport.class, getImportParams());
        errData.clear();
        data.clear();
        setCls(BasePdaExport.class);
        for (BasePdaExport bean : infos) {
            if (Tools.isFieldEmpty(bean)) {
                errData.add(bean);
                continue;
            }
            data.add(bean);
        }
    }

    @Override
    public ImportParams getImportParams() {
        ImportParams params = new ImportParams();
        params.setTitleRows(0);
        params.setHeadRows(1);
        params.setKeyIndex(1);
        return params;
    }
}
